#!/bin/bash

#[ -f $HOME/.xprofile ] && . $HOME/.xprofile

dwmstatusbar() {
    LANGUAGE=$( xset -q|grep LED| awk '{ if (substr ($10,5,1) == 1) print "RU"; else print "EN"; }' )
    DATE_TIME=$( date +"%a %b %d  %T" )
    CPU_USAGE=$(( 100-$(vmstat 1 2|tail -1|awk '{print $15}') ))
    BATTERY=$( upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | awk '{ print $2 }' )
    BATTERY_SHOW="  b:$BATTERY"
    # if $BATTERY is empty, i.e. it is not laptop
    if [ -z "$BATTERY" ]
    then
        BATTERY_SHOW=""
    fi

    xsetroot  -rv -name "$LANGUAGE  $DATE_TIME  c:$CPU_USAGE$BATTERY_SHOW"
}

setxkbmap -option
#setxkbmap -layout us,ru -option grp:lctrl_lwin_rctrl_menu
setxkbmap -layout us,ru -option grp:caps_select
#setxkbmap -layout us,ru -option grp:win_space_toggle

dunst &
pipewire &

xrandr --output eDP-1 --mode 1600x900
#xrandr --output Virtual-1 --mode 1920x1080
#xrandr --output HDMI-A-0 --auto --right-of eDP-1

xsetroot -gray
#feh --bg-scale  ~/Pictures/above-clouds.jpg
nm-applet &
xautolock -time 60 -locker slock &

# Statusbar loop
while true; do
    dwmstatusbar
    sleep 1s
done &

dbus-run-session dwm

